
***************************************************
*Table A.3
***************************************************

use "$workdata/baseline", clear /* see $data_do/baseline.do */

g e=1
g b_month=month(foed_dag)
g b_year=year(foed_dag)

collapse wage sa (sum) e, by(pnr age_q year month b_month b_year) 

capture drop age_month_q_y
g age_month_q_y=floor(age_q)
tostring age_month_q_y, replace
capture drop age_month_q_m
g age_month_q_m=(round((age_q-floor(age_q))*12)+1)/100
tostring age_month_q_m, replace
capture drop age_month_q
egen age_month_q=concat(age_month_q_y age_month_q_m)
destring age_month_q, replace
local resp="age_month_q>=24.12 & age_month_q<=25.04"
g resp=`resp'
g d=age_q>=25
g age_q0=age_q-25
g age_q0_2= age_q0^2
g age_q0_3= age_q0^3
g age_q0_4= age_q0^4
g dXage_q0=d*age_q0
g dXage_q0_2=d*age_q0_2
g dXage_q0_3=d*age_q0_3
g dXage_q0_4=d*age_q0_4

*********************************************************************
***************************************************
*Table A.3, No control
***************************************************
eststo clear
local model=0
foreach y of varlist sa wage {
preserve
collapse `y' if age_q>=21 & age_q<29, by(pnr age_q)
sum `y'
local obs=(r(N))
di `obs'
restore

preserve
keep if age_q>=21 & age_q<29


sum `y' if age_month_q==24.11
local initial=round(r(mean), 0.01)
di `initial'

forvalues s=5/5 {

local spec_num=`s'
if `y'==wage local title="Employment (residuals)"
if `y'==sa   local title="Social Assistance (residuals)"
if `y'==wage local fig_num=6
if `y'==sa local fig_num=2

if `spec_num'==1 local spec="d age_q0"
if `spec_num'==2 local spec="d age_q0 age_q0_2"
if `spec_num'==3 local spec="d age_q0 age_q0_2 age_q0_3"
if `spec_num'==4 local spec="d age_q0                   dXage_q0"
if `spec_num'==5 local spec="d age_q0 age_q0_2          dXage_q0 dXage_q0_2"

if `spec_num'==1 local spec_name="1st order polynomial"
if `spec_num'==2 local spec_name="2nd order polynomial"
if `spec_num'==3 local spec_name="3rd order polynomial"
if `spec_num'==4 local spec_name="1st order polynomial spline"
if `spec_num'==5 local spec_name="2nd order polynomial spline"


local model =`model'+1
local repl_app="append"
if `model'==1 local repl_app="replace"
eststo model`model': reg `y' `spec'  [aw=e] if resp==0 , vce(cluster pnr)
local N_clust=e(N_clust)
local pct_of_initial= round(((round(_b[d],0.001)/`initial')*100), 0.1)
di `pct_of_initial'

regsave d using $tables/tableA3_1 , addlabel(samplesize, `obs', N_clust,`N_clust',outcome,`y',spec,`spec_name',regnum,`model',initial,`initial',pct_of_initial,`pct_of_initial') `repl_app'

}
restore
}


***************************************************
*Table A.3, Control: Time
***************************************************
eststo clear
local model=0
foreach y of varlist sa wage {
preserve
collapse `y' if age_q>=21 & age_q<29, by(pnr age_q)
sum `y'
local obs=(r(N))
di `obs'
restore

preserve
keep if age_q>=21 & age_q<29


sum `y' if age_month_q==24.11
local initial=round(r(mean), 0.01)
di `initial'


reg `y' i.year##i.month  [aw=e]
predict res, r
replace `y'=res


forvalues s=5/5 {

local spec_num=`s'
if `y'==wage local title="Employment (residuals)"
if `y'==sa   local title="Social Assistance (residuals)"
if `y'==wage local fig_num=6
if `y'==sa local fig_num=2


if `spec_num'==1 local spec="d age_q0"
if `spec_num'==2 local spec="d age_q0 age_q0_2"
if `spec_num'==3 local spec="d age_q0 age_q0_2 age_q0_3"
if `spec_num'==4 local spec="d age_q0                   dXage_q0"
if `spec_num'==5 local spec="d age_q0 age_q0_2          dXage_q0 dXage_q0_2"

if `spec_num'==1 local spec_name="1st order polynomial"
if `spec_num'==2 local spec_name="2nd order polynomial"
if `spec_num'==3 local spec_name="3rd order polynomial"
if `spec_num'==4 local spec_name="1st order polynomial spline"
if `spec_num'==5 local spec_name="2nd order polynomial spline"


local model =`model'+1
local repl_app="append"
if `model'==1 local repl_app="replace"
eststo model`model': reg `y' `spec'  [aw=e] if resp==0 , vce(cluster pnr)
local N_clust=e(N_clust)
local pct_of_initial= round(((round(_b[d],0.001)/`initial')*100), 0.1)
di `pct_of_initial'

regsave d using $tables/tableA3_2 , addlabel(samplesize, `obs', N_clust,`N_clust',outcome,`y',spec,`spec_name',regnum,`model',initial,`initial',pct_of_initial,`pct_of_initial') `repl_app'

}
restore
}

***************************************************
*Table A.3, Control: Cohort
***************************************************
eststo clear
local model=0
foreach y of varlist sa wage {
preserve
collapse `y' if age_q>=21 & age_q<29, by(pnr age_q)
sum `y'
local obs=(r(N))
di `obs'
restore

preserve
keep if age_q>=21 & age_q<29


sum `y' if age_month_q==24.11
local initial=round(r(mean), 0.01)
di `initial'


reg `y'  i.b_year##i.b_month [aw=e]
predict res, r
replace `y'=res


forvalues s=5/5 {

local spec_num=`s'
if `y'==wage local title="Employment (residuals)"
if `y'==sa   local title="Social Assistance (residuals)"
if `y'==wage local fig_num=6
if `y'==sa local fig_num=2

if `spec_num'==1 local spec="d age_q0"
if `spec_num'==2 local spec="d age_q0 age_q0_2"
if `spec_num'==3 local spec="d age_q0 age_q0_2 age_q0_3"
if `spec_num'==4 local spec="d age_q0                   dXage_q0"
if `spec_num'==5 local spec="d age_q0 age_q0_2          dXage_q0 dXage_q0_2"

if `spec_num'==1 local spec_name="1st order polynomial"
if `spec_num'==2 local spec_name="2nd order polynomial"
if `spec_num'==3 local spec_name="3rd order polynomial"
if `spec_num'==4 local spec_name="1st order polynomial spline"
if `spec_num'==5 local spec_name="2nd order polynomial spline"


local model =`model'+1
local repl_app="append"
if `model'==1 local repl_app="replace"
eststo model`model': reg `y' `spec'  [aw=e] if resp==0 , vce(cluster pnr)
local N_clust=e(N_clust)
local pct_of_initial= round(((round(_b[d],0.001)/`initial')*100), 0.1)
di `pct_of_initial'

regsave d using $tables/tableA3_3 , addlabel(samplesize, `obs', N_clust,`N_clust',outcome,`y',spec,`spec_name',regnum,`model',initial,`initial',pct_of_initial,`pct_of_initial') `repl_app'

}
restore
}

***************************************************
*Table A.3, Control: Time and Cohort
***************************************************
eststo clear
local model=0
foreach y of varlist sa wage {
preserve
collapse `y' if age_q>=21 & age_q<29, by(pnr age_q)
sum `y'
local obs=(r(N))
di `obs'
restore

preserve
keep if age_q>=21 & age_q<29


sum `y' if age_month_q==24.11
local initial=round(r(mean), 0.01)
di `initial'


reg `y' i.year##i.month i.b_year##i.b_month [aw=e]
predict res, r
replace `y'=res


forvalues s=5/5 {

local spec_num=`s'
if `y'==wage local title="Employment (residuals)"
if `y'==sa   local title="Social Assistance (residuals)"
if `y'==wage local fig_num=6
if `y'==sa local fig_num=2

if `spec_num'==1 local spec="d age_q0"
if `spec_num'==2 local spec="d age_q0 age_q0_2"
if `spec_num'==3 local spec="d age_q0 age_q0_2 age_q0_3"
if `spec_num'==4 local spec="d age_q0                   dXage_q0"
if `spec_num'==5 local spec="d age_q0 age_q0_2          dXage_q0 dXage_q0_2"

if `spec_num'==1 local spec_name="1st order polynomial"
if `spec_num'==2 local spec_name="2nd order polynomial"
if `spec_num'==3 local spec_name="3rd order polynomial"
if `spec_num'==4 local spec_name="1st order polynomial spline"
if `spec_num'==5 local spec_name="2nd order polynomial spline"


local model =`model'+1
local repl_app="append"
if `model'==1 local repl_app="replace"
eststo model`model': reg `y' `spec'  [aw=e] if resp==0 , vce(cluster pnr)
local N_clust=e(N_clust)
local pct_of_initial= round(((round(_b[d],0.001)/`initial')*100), 0.1)
di `pct_of_initial'

regsave d using $tables/tableA3_4 , addlabel(samplesize, `obs', N_clust,`N_clust',outcome,`y',spec,`spec_name',regnum,`model',initial,`initial',pct_of_initial,`pct_of_initial') `repl_app'

}
restore
}


***************************************************
*Table A.3, Control: Time, Cohort and FE
***************************************************

eststo clear
local model=0
foreach y of varlist sa wage {
preserve
collapse `y' if age_q>=21 & age_q<29, by(pnr age_q)
sum `y'
local obs=(r(N))
di `obs'
restore

preserve
keep if age_q>=21 & age_q<29


sum `y' if age_month_q==24.11
local initial=round(r(mean), 0.01)
di `initial'


areg `y' i.year##i.month i.b_year##i.b_month [aw=e], absorb(pnr)
predict res, r
replace `y'=res


forvalues s=5/5 {

local spec_num=`s'
if `y'==wage local title="Employment (residuals)"
if `y'==sa   local title="Social Assistance (residuals)"
if `y'==wage local fig_num=6
if `y'==sa local fig_num=2

if `spec_num'==1 local spec="d age_q0"
if `spec_num'==2 local spec="d age_q0 age_q0_2"
if `spec_num'==3 local spec="d age_q0 age_q0_2 age_q0_3"
if `spec_num'==4 local spec="d age_q0                   dXage_q0"
if `spec_num'==5 local spec="d age_q0 age_q0_2          dXage_q0 dXage_q0_2"

if `spec_num'==1 local spec_name="1st order polynomial"
if `spec_num'==2 local spec_name="2nd order polynomial"
if `spec_num'==3 local spec_name="3rd order polynomial"
if `spec_num'==4 local spec_name="1st order polynomial spline"
if `spec_num'==5 local spec_name="2nd order polynomial spline"


local model =`model'+1
local repl_app="append"
if `model'==1 local repl_app="replace"
eststo model`model': reg `y' `spec'  [aw=e] if resp==0 , vce(cluster pnr)
local N_clust=e(N_clust)
local pct_of_initial= round(((round(_b[d],0.001)/`initial')*100), 0.1)
di `pct_of_initial'

regsave d using $tables/tableA3_5 , addlabel(samplesize, `obs', N_clust,`N_clust',outcome,`y',spec,`spec_name',regnum,`model',initial,`initial',pct_of_initial,`pct_of_initial') `repl_app'

}
restore
}

***************************************************
*end: Table A.3
***************************************************
